package com.lyf.lottery.controller;

import com.github.pagehelper.PageInfo;
import com.lyf.common.api.CommonPage;
import com.lyf.common.api.CommonResult;
import com.lyf.lottery.model.po.OptActivityBlindBox;
import com.lyf.lottery.model.req.OptActivityBlindBoxQuery;
import com.lyf.lottery.service.OptActivityBlindBoxService;
import com.lyf.lottery.model.vo.OptActivityBlindBoxAddVo;
import com.lyf.lottery.model.vo.OptActivityBlindBoxUpdateVo;
import com.lyf.lottery.model.vo.OptActivityBlindBoxQueryVo;
import com.lyf.lottery.model.vo.OptActivityBlindBoxVo;
import com.lyf.lottery.controller.assembler.OptActivityBlindBoxAssembler;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
 *  OptActivityBlindBox 接口
 * @author lyf
 **/
@RestController
@Api(tags = "OptActivityBlindBox接口")
@RequestMapping("/optActivity/blindBox")
public class OptActivityBlindBoxController {

	@Autowired
	private OptActivityBlindBoxService optActivityBlindBoxService;

	@PostMapping("/add")
	@ApiOperation("添加")
	public CommonResult add(@Validated @RequestBody OptActivityBlindBoxAddVo optActivityBlindBoxAddVo) {
		OptActivityBlindBox entity = OptActivityBlindBoxAssembler.INSTANCE.getOptActivityBlindBox(optActivityBlindBoxAddVo);
		optActivityBlindBoxService.insert(entity);
		return CommonResult.success(true);
	}

	@PostMapping("/update")
	@ApiOperation("修改")
	public CommonResult update(@Validated @RequestBody OptActivityBlindBoxUpdateVo optActivityBlindBoxUpdateVo) {
		OptActivityBlindBox entity = OptActivityBlindBoxAssembler.INSTANCE.getOptActivityBlindBox(optActivityBlindBoxUpdateVo);
		optActivityBlindBoxService.update(entity);
		return CommonResult.success(true);
	}
	@PostMapping("/putOn/{id}")
	@ApiOperation("上架")
	public CommonResult putOn(@PathVariable("id")Integer id) {
		return optActivityBlindBoxService.putOn(id);
	}
	@PostMapping("putDown/{id}")
	@ApiOperation("下架")
	public CommonResult putDown(@PathVariable("id")Integer id) {
		return optActivityBlindBoxService.putDown(id);
	}
	@GetMapping("/list")
	@ApiOperation("获取列表")
	public CommonResult<CommonPage<OptActivityBlindBoxVo>> selectPage(OptActivityBlindBoxQueryVo optActivityBlindBoxQueryVo) {
		OptActivityBlindBoxQuery query = OptActivityBlindBoxAssembler.INSTANCE.getOptActivityBlindBoxQuery(optActivityBlindBoxQueryVo);
		PageInfo<OptActivityBlindBox> pageInfo = optActivityBlindBoxService.selectPage(query);
		PageInfo<OptActivityBlindBoxVo> resultPage = OptActivityBlindBoxAssembler.INSTANCE.convertPageInfo(pageInfo);
		return CommonResult.success(CommonPage.restPage(resultPage));
	}

}

